<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <span id="control" th:attr="data-status=${status}" style="display: block;"></span>
    <!-- IF STATUS IS '1' -->
<div th:if="${status} eq '1'">
    <h1>秒杀进行中...</h1>
    <span id="leftTime" th:attr="data=${leftTime}"></span>
 </div>
 <!-- ELSE -->
 <div th:if="${status} eq '0'">
    <h1>秒杀已结束！</h1>
 </div>
 <div th:if="${status} eq '2'">
    <h1>秒杀未开始！</h1>
 </div>
    
<form action="/kill">
    <div>
        商品：
        <input type="radio" name="name" value="product">拉勾限量版iphone  ￥5999<br>
        库存:<span th:if="${status} eq '0'">0</span>
            <span th:if="${status} eq '1'" th:text="${stock}">100</span>
            <span th:if="${status} eq '2'">100</span>        
    </div>
    <div>
        数量：<input name="count" value="1"> (限购1件）
    </div>
    <button id="btn-kill" th:disabled="${status == '0'} ? 'true':'false'" type="submit">一键下单</button>
</form>
</body>
<script>
    if(document.getElementById("control").getAttribute("data-status") == "1"){
        var maxtime = parseInt(document.getElementById("leftTime").getAttribute("data")); 
        // var maxtime = parseInt(); //一个小时，按秒计算，自己调整!
        function CountDown() {
                if (maxtime >= 0) {
                        minutes = Math.floor(maxtime / 60);
                        seconds = Math.floor(maxtime % 60);
                        msg = "距离抢购结束还有" + minutes + "分" + seconds + "秒";
                        document.getElementById("leftTime").innerHTML = msg;
                        if (maxtime == 5 * 60)alert("还剩5分钟");
                            --maxtime;
                    } else{
                        clearInterval(timer);
                        document.getElementById("btn-kill").setAttribute("disabled", "true");
                        console.log(btn);
                        // btn.setAttdisabled = true;
                        alert("时间到，结束!");
                    }
            }
        timer = setInterval("CountDown()", 1000);
    }
</script>
</html>